package cn.neusoft.yp.service.impl;

import cn.neusoft.yp.mapper.UserMapper;
import cn.neusoft.yp.pojo.User;
import cn.neusoft.yp.service.UserService;
import cn.neusoft.yp.tool.MD5Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * Created by gaosheng on 2017/4/27.
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper ;

    public void saveUser(User user) {

        //设置新增用户的ID
        String id= UUID.randomUUID().toString();
        user.setId(id);

        //用加密算法给密码加密
        String password= MD5Hash.getMd5Password(user.getUsername(),user.getPassword() );
        user.setPassword(password);

        userMapper.saveUser(user);
    }

    public User findUserByUsername(String username) {
        return userMapper.findUserByUsername(username);
    }

    public List<User> findAll() {
        return userMapper.findAll();
    }
}
